/*
 * loader.c
 *
 * Created: 15.04.2013 15:48:41
 *  Author: saenko
 */ 



#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>


#include "SPI.h"
#include "ad5291.h"
#include "ADC.h"
#include "uart.h"

unsigned char ADC_data_0;
unsigned char ADC_data_1;
unsigned int vol_temp;

int main(void)
{
	spi_init();
	uart_init();

	sei();
	
	printstr_p(PSTR("UART OK\n"));


    ad5291_set_vol(0x0032);
	
	ADC_init(0,1);

    while(1)
    {
		
		//-----------------------------------
		
		ADC_init(0,1);		
	    ADC_data_0 = ADC_measure();	
		
		ADC_init(1,3);
		ADC_data_1 = ADC_measure();		
			
		putchr('A');putchr('S');puchtr('D');
		
		putchr(ADC_data_0);
		
		putchr(ADC_data_1);
		
		_delay_ms(50);
	//	putchr('Q');
		
	//	for(;;);
		
		//-----------------------------------
		
		
       if(uart_flags.rxstring_end)
		  {
			uart_flags.rxstring_end = 0;	
			

					vol_temp = 0;
					vol_temp = 8<<vol_temp;
					vol_temp += rxstring[3];
					
					    ad5291_set_vol(vol_temp);

			

		}	
		
				_delay_ms(50); 
    }
}